﻿function bl() {
    var codes = new Array();

    // 复制 BLL/BLS 文件夹
    codes.push({
        type: 'copy',
        isfolder: true,
        source: set.VSVersion + '\\' + set.BLFrame,
        target: set.BLFrame
    });

    // 业务逻辑层基类
    codes.push(blHelper());

    // 逐表生成
    for (var i = 0; i < db.Selects.length; i++) {
        var tableName = db.Selects[i];
        codes.push(tableInternalBll(tableName));
        codes.push(tableEditableBll(tableName));
        if (set.BLFrame == 'BLS') {
            codes.push(blasmx(tableName));
        }
    }

    return codes;
}

function blHelper() {
    var NewLine = '\n';
    var temp = '';
    temp += 'using System;' + NewLine;
    temp += 'using System.Collections;' + NewLine;
    temp += 'using System.Configuration;' + NewLine;
    temp += 'using System.Web;' + NewLine;
    temp += 'using System.Web.Caching;' + NewLine;
    temp += NewLine;
    temp += 'namespace {0}'.format(getNamespace(set.BLFrame)) + NewLine;
    temp += '{' + NewLine;
    temp += '    /// <summary>' + NewLine;
    temp += '    /// 业务逻辑层基类' + NewLine;
    temp += '    /// </summary>' + NewLine;
    temp += '    public class BLHelper' + NewLine;
    temp += '    {' + NewLine;
    temp += '        private static readonly string CACHEHEADER_MODEL = "Model_";' + NewLine;
    temp += '        private static readonly string CACHEHEADER_LIST = "List_";' + NewLine;
    temp += NewLine;
    temp += '        /// <summary>' + NewLine;
    temp += '        /// 是否启用缓存' + NewLine;
    temp += '        /// </summary>' + NewLine;
    temp += '        protected static readonly bool EnableCache = Convert.ToBoolean(ConfigurationManager.AppSettings["EnableCache"]);' + NewLine;
    temp += NewLine;
    temp += '        public BLHelper() { }' + NewLine;
    temp += NewLine;
    temp += '        /// <summary>' + NewLine;
    temp += '        /// 缓存key的头部' + NewLine;
    temp += '        /// </summary>' + NewLine;
    temp += '        protected string basicKey;' + NewLine;
    temp += NewLine;
    temp += '        /// <summary>' + NewLine;
    temp += '        /// 构造函数,请传入basicKey' + NewLine;
    temp += '        /// </summary>' + NewLine;
    temp += '        public BLHelper(string basicKey)' + NewLine;
    temp += '        {' + NewLine;
    temp += '            this.basicKey = basicKey;' + NewLine;
    temp += '        }' + NewLine;
    temp += NewLine;
    temp += '        #region 缓存操作' + NewLine;
    temp += NewLine;
    temp += '        /// <summary>' + NewLine;
    temp += '        /// 建立一个Model缓存' + NewLine;
    temp += '        /// </summary>' + NewLine;
    temp += '        protected void TryAddModelCache(object modelKey, object value, CacheDependency dependencies, DateTime absoluteExpiration, TimeSpan slidingExpiration, CacheItemPriority priority, CacheItemRemovedCallback onRemovedCallback)' + NewLine;
    temp += '        {' + NewLine;
    temp += '            string key = basicKey + CACHEHEADER_MODEL + modelKey.ToString();' + NewLine;
    temp += '            CacheHelper.TryAddCache(key, value, dependencies, absoluteExpiration, slidingExpiration, priority, onRemovedCallback);' + NewLine;
    temp += '        }' + NewLine;
    temp += NewLine;
    temp += '        /// <summary>' + NewLine;
    temp += '        /// 获取一个Model缓存' + NewLine;
    temp += '        /// </summary>' + NewLine;
    temp += '        protected object GetModelCache(object modelKey)' + NewLine;
    temp += '        {' + NewLine;
    temp += '            return CacheHelper.GetCache(basicKey + CACHEHEADER_MODEL + modelKey.ToString());' + NewLine;
    temp += '        }' + NewLine;
    temp += NewLine;
    temp += '        /// <summary>' + NewLine;
    temp += '        /// 删除一个Model缓存' + NewLine;
    temp += '        /// </summary>' + NewLine;
    temp += '        protected void RemoveModelCache(object modelKey)' + NewLine;
    temp += '        {' + NewLine;
    temp += '            CacheHelper.TryRemoveCache(basicKey + CACHEHEADER_MODEL + modelKey.ToString());' + NewLine;
    temp += '        }' + NewLine;
    temp += NewLine;
    temp += '        /// <summary>' + NewLine;
    temp += '        /// 删除所有Model缓存' + NewLine;
    temp += '        /// </summary>' + NewLine;
    temp += '        protected void RemoveModelCache()' + NewLine;
    temp += '        {' + NewLine;
    temp += '            CacheHelper.RemoveMultiCache(basicKey + CACHEHEADER_MODEL);' + NewLine;
    temp += '        }' + NewLine;
    temp += NewLine;
    temp += '        /// <summary>' + NewLine;
    temp += '        /// 建立一个List缓存' + NewLine;
    temp += '        /// </summary>' + NewLine;
    temp += '        protected void TryAddListCache(object listKey, object value, CacheDependency dependencies, DateTime absoluteExpiration, TimeSpan slidingExpiration, CacheItemPriority priority, CacheItemRemovedCallback onRemovedCallback)' + NewLine;
    temp += '        {' + NewLine;
    temp += '            string key = basicKey + CACHEHEADER_LIST + listKey.ToString();' + NewLine;
    temp += '            CacheHelper.TryAddCache(key, value, dependencies, absoluteExpiration, slidingExpiration, priority, onRemovedCallback);' + NewLine;
    temp += '        }' + NewLine;
    temp += NewLine;
    temp += '        /// <summary>' + NewLine;
    temp += '        /// 获取一个List缓存' + NewLine;
    temp += '        /// </summary>' + NewLine;
    temp += '        protected object GetListCache(object listKey)' + NewLine;
    temp += '        {' + NewLine;
    temp += '            return CacheHelper.GetCache(basicKey + CACHEHEADER_LIST + listKey.ToString());' + NewLine;
    temp += '        }' + NewLine;
    temp += NewLine;
    temp += '        /// <summary>' + NewLine;
    temp += '        /// 删除一个List缓存' + NewLine;
    temp += '        /// </summary>' + NewLine;
    temp += '        protected void RemoveListCache(object listKey)' + NewLine;
    temp += '        {' + NewLine;
    temp += '            CacheHelper.TryRemoveCache(basicKey + CACHEHEADER_LIST + listKey.ToString());' + NewLine;
    temp += '        }' + NewLine;
    temp += NewLine;
    temp += '        /// <summary>' + NewLine;
    temp += '        /// 删除所有List缓存' + NewLine;
    temp += '        /// </summary>' + NewLine;
    temp += '        protected void RemoveListCache()' + NewLine;
    temp += '        {' + NewLine;
    temp += '            CacheHelper.RemoveMultiCache(basicKey + CACHEHEADER_LIST);' + NewLine;
    temp += '        }' + NewLine;
    temp += NewLine;
    temp += '        #endregion' + NewLine;
    temp += '    }' + NewLine;
    temp += '}' + NewLine;

    return {
        type: 'code',
        title: 'BLHelper',
        path: set.BLFrame + '\\BLHelper.cs',
        code: temp
    };
}

function tableInternalBll(table) {
    var bllClassName = getBllClassName(table.Name);
    var dalClassName = getDalClassName(table.Name);
    var dalClassNameWithoutNamespace = getDalClassName(table.Name);
    var dalClassNameWithNamespace = getNamespace('DAL') + '.' + dalClassNameWithoutNamespace;
    var modelClassNameWithoutNamespace = getModelClassName(table.Name);
    var modelClassNameWithNamespace = getNamespace('Model') + '.' + modelClassNameWithoutNamespace;
    var modelIDClassNameWithoutNamespace = modelClassNameWithoutNamespace + "_ID";
    var modelIDClassNameWithNamespace = modelClassNameWithNamespace + "_ID";
    var condFields = table.CondFields;
    var uncondFields = table.UncondFields;
    var allFields = table.Fields;
    var hasCompositeKey = condFields.length > 1;
    var modelIDPropertyName = hasCompositeKey ? modelIDClassNameWithoutNamespace : table.CondFields[0].Name; //数据模型类的标识属性的名称
    var modelIDPropertyType = hasCompositeKey ? modelIDClassNameWithNamespace : csType[table.CondFields[0].DbType];//数据模型类的标识属性的.Net类型

    var NewLine = '\n';
    var temp = '';
    temp += 'using System;' + NewLine;
    if (set.BLFrame == 'BLS') {
        temp += 'using System.Web.Services;' + NewLine;
        temp += 'using System.ComponentModel;' + NewLine;
    }
    temp += 'using System.Collections.Generic;' + NewLine;
    temp += 'using System.Text.RegularExpressions;' + NewLine;
    temp += 'using DBUtility;' + NewLine;
    temp += 'using System.Runtime.Caching;' + NewLine;
    if (set.CacheFrame == 'ListCache')
        temp += 'using System.Linq;' + NewLine;
    if (set.SlnFrame == 'Factory')
        temp += 'using DALFactory;' + NewLine;
    temp += NewLine;
    temp += 'namespace {0}'.format(getNamespace(set.BLFrame)) + NewLine;
    temp += '{' + NewLine;
    temp += '    /// <summary>' + NewLine;
    temp += '    /// 业务逻辑类 {0}  - 请勿修改此文件，以方便表字段更改时重新生成覆盖 '.format(table.Descn) + NewLine;
    temp += '    /// </summary>' + NewLine;
    if (set.BLFrame == 'BLS') {
        temp += '    [WebService(Namespace = "http://www.Socansoft.com/")]' + NewLine;
        temp += '    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]' + NewLine;
        temp += '    [ToolboxItem(false)]' + NewLine;
    }
    temp += '    public partial class {0}: BLHelper<{0}>'.format(bllClassName) + NewLine;
    temp += '    {' + NewLine;
    temp += NewLine;
    temp += '        private {0}() {}'.format(bllClassName) + NewLine;
    temp += NewLine;
    temp += getComment('增加一条数据');
    temp += '        public static void Add({0} model)'.format(modelClassNameWithNamespace) + NewLine;
    temp += '        {' + NewLine;
    switch (set.CacheFrame) {
        case 'ListCache':
            temp += '            bool inserted =  {0}.Add(model);'.format(dalClassNameWithNamespace) + NewLine;
            temp += '            if (EnableCache && inserted)' + NewLine;
            temp += '            {' + NewLine;
            temp += '                RemoveListCache();' + NewLine;
            temp += '            }' + NewLine;
            break;
        case 'ObjectCache':
            temp += '            bool inserted =  {0}.Add(model);'.format(dalClassNameWithNamespace) + NewLine;
            temp += '            if (EnableCache && inserted)' + NewLine;
            temp += '            {' + NewLine;
            temp += '                SetExistCache(model.{0}, true);'.format(modelIDPropertyName) + NewLine;
            temp += '                SetModelCache(model.{0}, model);'.format(modelIDPropertyName) + NewLine;
            temp += '                RemoveCountCache();' + NewLine;
            temp += '            }' + NewLine;
            break;
        default:
            temp += '            {0}.Add(model);'.format(dalClassNameWithNamespace) + NewLine;
            break;
    }
    temp += '        }' + NewLine;
    temp += NewLine;
    temp += getComment('更新一条数据');
    temp += '        public static void Update({0} model)'.format(modelClassNameWithNamespace) + NewLine;
    temp += '        {' + NewLine;
    switch (set.CacheFrame) {
        case 'ObjectCache':
            temp += '            bool updated = {0}.Update(model);'.format(dalClassNameWithNamespace) + NewLine;
            temp += '            if (EnableCache && updated)' + NewLine;
            temp += '            {' + NewLine;
            temp += '                SetExistCache(model.{0}, true);'.format(modelIDPropertyName) + NewLine;
            temp += '                SetModelCache(model.{0}, model);'.format(modelIDPropertyName) + NewLine;
            temp += '                RemoveCountCache();' + NewLine;
            temp += '            }' + NewLine;
            break;
        case 'ListCache':
            temp += '            bool updated = {0}.Update(model);'.format(dalClassNameWithNamespace) + NewLine;
            temp += '            if (EnableCache && updated)' + NewLine;
            temp += '            {' + NewLine;
            temp += '                RemoveListCache();' + NewLine;
            temp += '            }' + NewLine;
            break;
        default:
            temp += '            {0}.Update(model);'.format(dalClassNameWithNamespace) + NewLine;
            break;
    }
    temp += '        }' + NewLine;
    temp += NewLine;
    temp += getComment('删除一条数据');
    temp += '        public static void Delete({0} id)'.format(modelIDPropertyType) + NewLine;
    temp += '        {' + NewLine;
    switch (set.CacheFrame) {
        case 'ObjectCache':
            temp += '            bool deleted = {0}.Delete(id);'.format(dalClassNameWithNamespace) + NewLine;
            temp += '            if (EnableCache && deleted)' + NewLine;
            temp += '            {' + NewLine;
            temp += '                SetExistCache(id, false);' + NewLine;
            temp += '                RemoveModelCache(id);' + NewLine;
            temp += '                RemoveCountCache();' + NewLine;
            temp += '            }' + NewLine;
            break;
        case 'ListCache':
            temp += '            bool deleted = {0}.Delete(id);'.format(dalClassNameWithNamespace) + NewLine;
            temp += '            if (EnableCache && deleted)' + NewLine;
            temp += '            {' + NewLine;
            temp += '                RemoveListCache();' + NewLine;
            temp += '            }' + NewLine;
            break;
        default:
            temp += '            deleted = {0}.Delete(id);'.format(dalClassNameWithNamespace) + NewLine;
            break;
    }
    temp += '        }' + NewLine;
    temp += NewLine;
    if (hasCompositeKey) {
        temp += getComment('删除一条数据');
        temp += '        public static void Delete({0})'.format(getFuncParm(table, true)) + NewLine;
        temp += '        {' + NewLine;
        temp += '            Delete(new {0}({1}));'.format(modelIDPropertyType, getFuncParm(table, false)) + NewLine;
        temp += '        }' + NewLine;
        temp += NewLine;
    }
    temp += getComment('是否存在该记录');
    temp += '        public static bool IsExist({0} id)'.format(modelIDPropertyType) + NewLine;
    temp += '        {' + NewLine;
    switch (set.CacheFrame) {
        case 'ListCache':
            temp += '            List<{0}> lst = GetList();'.format(modelClassNameWithNamespace) + NewLine;
            temp += '            return (from m in lst where id.Equals(m.{0}) select m).Any();'.format(modelIDPropertyName) + NewLine;
            break;
        case 'ObjectCache':
            temp += '            if (EnableCache)' + NewLine;
            temp += '            {' + NewLine;
            temp += '                bool? exist = GetExistCache(id);' + NewLine;
            temp += '                if (exist.HasValue)' + NewLine;
            temp += '                {' + NewLine;
            temp += '                    return exist.Value;' + NewLine;
            temp += '                }' + NewLine;
            temp += '                exist = {0}.IsExist(id);'.format(dalClassNameWithNamespace) + NewLine;
            temp += '                SetExistCache(id, exist.Value);' + NewLine;
            temp += '                return exist.Value;' + NewLine;
            temp += '            }' + NewLine;
            temp += '            return {0}.IsExist(id);'.format(dalClassNameWithNamespace) + NewLine;
            break;
        default:
            temp += '            return {0}.IsExist(id);'.format(dalClassNameWithNamespace) + NewLine;
            break;
    }
    temp += '        }' + NewLine;
    temp += NewLine;
    if (hasCompositeKey) {
        temp += getComment('是否存在该记录');
        temp += '        public static bool IsExist({0})'.format(getFuncParm(table, true)) + NewLine;
        temp += '        {' + NewLine;
        temp += '            return IsExist(new {0}({1}));'.format(modelIDPropertyType, getFuncParm(table, false)) + NewLine;
        temp += '        }' + NewLine;
        temp += NewLine;
    }
    temp += getComment('得到一个对象实体');
    temp += '        public static {0} GetModel({1} id)'.format(modelClassNameWithNamespace, modelIDPropertyType) + NewLine;
    temp += '        {' + NewLine;
    switch (set.CacheFrame) {
        case 'ObjectCache':
            temp += '            {0} model = null;'.format(modelClassNameWithNamespace) + NewLine;
            temp += '            if (!EnableCache)' + NewLine;
            temp += '            {' + NewLine;
            temp += '                model = {0}.GetModel(id);'.format(dalClassNameWithNamespace) + NewLine;
            temp += '            }' + NewLine;
            temp += '            else' + NewLine;
            temp += '            {' + NewLine;
            temp += '                model = GetModelCache(id) as {0};'.format(modelClassNameWithNamespace) + NewLine;
            temp += '                if(model == null)' + NewLine;
            temp += '                {' + NewLine;
            temp += '                    model = {0}.GetModel(id);'.format(dalClassNameWithNamespace) + NewLine;
            temp += '                    SetModelCache(id, model);' + NewLine;
            temp += '                }' + NewLine;
            temp += '            }' + NewLine;
            temp += '            return model;' + NewLine;
            break;
        case 'ListCache':
            temp += '            List<{0}> lst = GetList();'.format(modelClassNameWithNamespace) + NewLine;
            temp += '            {0} model = (from m in lst where id.Equals(m.{1}) select m).SingleOrDefault();'.format(modelClassNameWithNamespace, modelIDPropertyName) + NewLine;
            temp += '            return model;' + NewLine;
            break;
        default:
            temp += '            {0} model = {1}.GetModel(id);'.format(modelClassNameWithNamespace, dalClassNameWithNamespace) + NewLine;
            temp += '            return model;' + NewLine;
            break;
    }
    temp += '        }' + NewLine;
    temp += NewLine;
    if (hasCompositeKey) {
        temp += getComment('得到一个对象实体');
        temp += '        public static {0} GetModel({1})'.format(modelClassNameWithNamespace, getFuncParm(table, true)) + NewLine;
        temp += '        {' + NewLine;
        temp += '            return GetModel(new {0}({1}));'.format(modelIDPropertyType, getFuncParm(table, false)) + NewLine;
        temp += '        }' + NewLine;
        temp += NewLine;
    }
    temp += '        /// <summary>' + NewLine;
    temp += '        /// 删除多条数据' + NewLine;
    temp += '        /// </summary>' + NewLine;
    temp += '        public static bool Delete({0}[] ids, out string errMsg)'.format(modelIDPropertyType) + NewLine;
    temp += '        {' + NewLine;
    temp += '            var result = {0}.Delete(ids, out errMsg);'.format(dalClassNameWithNamespace) + NewLine;
    temp += '            if (EnableCache)' + NewLine;
    temp += '            {' + NewLine;
    temp += '                for (int i = 0; i < ids.Length; ++i)' + NewLine;
    temp += '                {' + NewLine;
    temp += '                    RemoveModelCache(ids[i].ToString());' + NewLine;
    temp += '                    SetExistCache(ids[i], false);' + NewLine;
    temp += '                }' + NewLine;
    temp += '                RemoveCountCache();' + NewLine;
    temp += '            }' + NewLine;
    temp += '            return result;' + NewLine;
    temp += '        }' + NewLine;
    temp += '        /// <summary>' + NewLine;
    temp += '        /// 删除所有数据' + NewLine;
    temp += '        /// </summary>' + NewLine;
    temp += '        public static void DeleteAll()' + NewLine;
    temp += '        {' + NewLine;
    temp += '            {0}.DeleteAll();'.format(dalClassNameWithNamespace) + NewLine;
    temp += '            if (EnableCache)' + NewLine;
    temp += '            {' + NewLine;
    temp += '                RemoveModelCache();' + NewLine;
    temp += '                SetAllExistCacheToFalse();' + NewLine;
    temp += '                SetCountCache(0);' + NewLine;
    temp += '            }' + NewLine;
    temp += '        }' + NewLine;
    temp += '        /// <summary>' + NewLine;
    temp += '        /// 获取数量' + NewLine;
    temp += '        /// </summary>' + NewLine;
    temp += '        public static int GetCount()' + NewLine;
    temp += '        {' + NewLine;
    temp += '            if (!EnableCache)' + NewLine;
    temp += '            {' + NewLine;
    temp += '                return {0}.GetCount();'.format(dalClassNameWithNamespace) + NewLine;
    temp += '            }' + NewLine;
    temp += '            else' + NewLine;
    temp += '            {' + NewLine;
    temp += '                int? count = GetCountCache();' + NewLine;
    temp += '                if (count.HasValue)' + NewLine;
    temp += '                {' + NewLine;
    temp += '                    return count.Value;' + NewLine;
    temp += '                }' + NewLine;
    temp += '                else' + NewLine;
    temp += '                {' + NewLine;
    temp += '                    count = {0}.GetCount();'.format(dalClassNameWithNamespace) + NewLine;
    temp += '                    SetCountCache(count.Value);' + NewLine;
    temp += '                    return count.Value;' + NewLine;
    temp += '                }' + NewLine;
    temp += '            }' + NewLine;
    temp += '        }' + NewLine;
    temp += NewLine;
    temp += getComment('获得泛型数据列表');
    temp += '        public static IList<{0}> GetAll()'.format(modelClassNameWithNamespace) + NewLine;
    temp += '        {' + NewLine;
    switch (set.CacheFrame) {
        case 'ListCache':
            temp += '            List<{0}> lst = null;'.format(modelClassNameWithNamespace) + NewLine;
            temp += '            if (!EnableCache)' + NewLine;
            temp += '            {' + NewLine;
            temp += '                lst = {0}.GetList();'.format(dalClassNameWithNamespace) + NewLine;
            temp += '            }' + NewLine;
            temp += '            else' + NewLine;
            temp += '            {' + NewLine;
            temp += '                string key = "ALL";' + NewLine;
            temp += '                if (GetListCache(key) != null)' + NewLine;
            temp += '                {' + NewLine;
            temp += '                    lst = GetListCache(key) as List<{0}>;'.format(modelClassNameWithNamespace) + NewLine;
            temp += '                }' + NewLine;
            temp += '                else' + NewLine;
            temp += '                {' + NewLine;
            temp += '                    lst = {0}.GetList();'.format(dalClassNameWithNamespace) + NewLine;
            temp += '                    TryAddListCache(key, lst, null, Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration, CacheItemPriority.Normal, null);' + NewLine;
            temp += '                }' + NewLine;
            temp += '            }' + NewLine;
            temp += NewLine;
            break;
        case 'ObjectCache':
            temp += '            var lst = {0}.GetAll();'.format(dalClassNameWithNamespace) + NewLine;
            temp += '            if(EnableCache)' + NewLine;
            temp += '            {' + NewLine;
            temp += '                SetCountCache(lst != null ? lst.Count : 0);' + NewLine;
            temp += '            }' + NewLine;
            break;
        default:
            temp += '            List<{0}> lst = {1}.GetList();'.format(modelClassNameWithNamespace, dalClassNameWithNamespace) + NewLine;
            break;;
    }
    temp += '            return lst;' + NewLine;
    temp += '        }' + NewLine;
    temp += NewLine;
    temp += getComment('分页获取泛型数据列表');
    temp += '        public static PageList<{0}> GetPageList(PageInfo pi)'.format(modelClassNameWithNamespace) + NewLine;
    temp += '        {' + NewLine;
    if (set.CacheFrame == 'ListCache') {
        temp += '            List<{0}> lst = GetList();'.format(modelClassNameWithNamespace) + NewLine;
        temp += '            pi.RecordCount = lst.Count;' + NewLine;
        temp += '            pi.Compute();' + NewLine;
        temp += '            PageList<{0}> pl = new PageList<{0}>(pi);'.format(modelClassNameWithNamespace) + NewLine;
        temp += '            pl.List = lst.Skip(pi.FirstIndex).Take(pi.PageSize).ToList();' + NewLine;
    } else {
        temp += '            PageList<{0}> pl = {1}.GetPageList(pi);'.format(modelClassNameWithNamespace, dalClassNameWithNamespace) + NewLine;
    }
    temp += '            return pl;' + NewLine;
    temp += '        }' + NewLine;
    temp += '        /// <summary>' + NewLine;
    temp += '        /// 分页获取泛型数据列表（带查询条件）' + NewLine;
    temp += '        /// </summary>' + NewLine;
    temp += '        public static PageList<{0}> GetPageListByFilter(PageInfo pi, params FilterInfo[] filters)'.format(modelClassNameWithNamespace) + NewLine;
    temp += '        {' + NewLine;
    temp += '            return {0}.GetPageListByFilter(pi, filters);'.format(dalClassNameWithNamespace) + NewLine;
    temp += '        }' + NewLine;
    temp += NewLine;
    temp += '        /// <summary>' + NewLine;
    temp += '        /// 根据查询条件数据列表' + NewLine;
    temp += '        /// </summary>' + NewLine;
    temp += '        public static IList<{0}> GetListByFilter(params FilterInfo[] filters)'.format(modelClassNameWithNamespace) + NewLine;
    temp += '        {' + NewLine;
    temp += '            return {0}.GetListByFilter(filters);'.format(dalClassNameWithNamespace) + NewLine;
    temp += '        }' + NewLine;
    temp += NewLine;
    temp += '        /// <summary>' + NewLine;
    temp += '        /// 根据查询条件数据列表' + NewLine;
    temp += '        /// </summary>' + NewLine;
    temp += '	    /// <summary>' + NewLine;
    temp += '        /// 根据查询条件数据列表' + NewLine;
    temp += '        /// </summary>' + NewLine;
    temp += '        /// <param name="filter">查询条件</param>' + NewLine;
    temp += '        /// <param name="orderby">排序字段列表</param>' + NewLine;
    temp += '        /// <returns>查询结果</returns>' + NewLine;
    temp += '        public static IList<{0}> GetListByFilter(IFilterInfo filter, params string[] orderby)'.format(modelClassNameWithNamespace) + NewLine;
    temp += '        {' + NewLine;
    temp += '            return {0}.GetListByFilter(filter, orderby);'.format(dalClassNameWithNamespace) + NewLine;
    temp += '        }' + NewLine;
    temp += NewLine;
    temp += '    }' + NewLine;
    temp += '}' + NewLine;


    function getComment(content) {
        var temp = '';
        var NewLine = '\n';
        switch (set.BLFrame) {
            case 'BLL':
                temp += '        /// <summary>' + NewLine;
                temp += '        /// {0}'.format(content) + NewLine;
                temp += '        /// </summary>' + NewLine;
                break;
            case 'BLS':
            default:
                temp += '        [WebMethod(Description="{0}")]'.format(content) + NewLine;
                break;
        }
        return temp;
    }

    return {
        title: set.BLFrame,
        path: '{0}\\internal\\{1}{2}.cs'.format(set.BLFrame, bllClassName, set.BLFrame == 'BLS' ? '.asmx' : ''),
        code: temp
    }
}

function tableEditableBll(table) {
    var bllClassName = getBllClassName(table.Name);
    var dalClassName = getDalClassName(table.Name);
    var dalClassNameWithoutNamespace = getDalClassName(table.Name);
    var dalClassNameWithNamespace = getNamespace('DAL') + '.' + dalClassNameWithoutNamespace;
    var modelClassNameWithoutNamespace = getModelClassName(table.Name);
    var modelClassNameWithNamespace = getNamespace('Model') + '.' + modelClassNameWithoutNamespace;
    var NewLine = '\n';
    var temp = '';
    temp += 'using System;' + NewLine;
    temp += 'using System.Collections.Generic;' + NewLine;
    temp += 'using System.Text.RegularExpressions;' + NewLine;
    temp += 'using System.Web;' + NewLine;
    temp += 'using System.Web.Caching;' + NewLine;
    temp += NewLine;
    temp += 'namespace {0}'.format(getNamespace(set.BLFrame)) + NewLine;
    temp += '{' + NewLine;
    temp += '    /// <summary>' + NewLine;
    temp += '    /// 业务逻辑类 ' + table.Descn + NewLine;
    temp += '    /// </summary>' + NewLine;
    temp += '    public partial class {0}'.format(bllClassName) + NewLine;
    temp += '    {' + NewLine;
    temp += '    }' + NewLine;
    temp += '}' + NewLine;

    return {
        title: set.BLFrame,
        path: '{0}\\editable\\{1}{2}.cs'.format(set.BLFrame, bllClassName, set.BLFrame == 'BLS' ? '.asmx' : ''),
        code: temp
    }
}

function blasmx(table) {
    var temp = '<%@ WebService Language="C#" CodeBehind="{1}.asmx.cs" Class="{0}.{1}" %>'.format(getNamespace('Model'), table.Name);
    return {
        title: '{0}.asmx'.format(set.BLFrame),
        path: '{0}\\{1}.asmx'.format(set.BLFrame, table.Name),
        code: temp
    };
}